home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Die Speccy' 97
/
Die Speccy' 97.iso
/
amiga_system
/
the_aminet
/
util
/
libs
/
mufs_usergroup.lha
/
usergroup
/
initgroups.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
3KB
|
100 lines
RCS_ID_C="$Id: initgroups.c,v 1.3 1994/01/21 12:34:52 ppessi Exp $";
/*
* initgroups.c - group initialization function
*
* Author: ppessi <Pekka.Pessi@hut.fi>
*
* This file is part of the AmiTCP/IP usergroup.library
*
* Copyright ⌐ 1993 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
* Helsinki University of Technology, Finland.
*
* Created : Sun Nov 28 17:45:55 1993 ppessi
* Last modified: Fri Jan 21 11:00:41 1994 ppessi
*
* $Log: initgroups.c,v $
* Revision 1.3 1994/01/21 12:34:52 ppessi
* Fixed NI_MEMBERS interface
*
* Revision 1.2 1994/01/21 08:13:47 ppessi
* Updated documentation
*
* Revision 1.1 1994/01/19 10:04:56 ppessi
* Initial revision
*
*/
/****** usergroup.library/initgroups ***************************************
NAME
initgroups - initialize group access list
SYNOPSIS
error = initgroups(name, basegid)
D0 A0 D0
int initgroups(const char *, gid_t);
FUNCTION
The initgroups() function reads through the group file and sets up,
the group access list for the user specified in name. The basegid is
automatically included in the groups list. Typically this value is
given as the group number from the password file.
RESULT
The initgroups() function returns -1 if the process has got no
necessary privileges, zero if the call is succesful.
FILES
AmiTCP:db/group
SEE ALSO
setgroups()
HISTORY
The initgroups function appeared in 4.2BSD.
****************************************************************************
*/
#include "base.h"
#include "libfunc.h"
SAVEDS ASM int R_initgroups(REG(a1) const char *name, REG(d0) gid_t basegroup)
{
struct NetInfoReq *nreq;
short error = -1;
ObtainSemaphore(ni_lock);
if (nreq = OpenNIUnit(NETINFO_GROUP_UNIT)) {
gid_t *groups = nreq->io_Data;
short ngroups, i, j;
groups[0] = basegroup;
nreq->io_Data = groups + 1;
nreq->io_Offset = (LONG) name;
nreq->io_Command = NI_MEMBERS;
if (myDoIO(nreq) == 0 || nreq->io_Error == NIERR_TOOSMALL) {
ngroups = nreq->io_Actual / sizeof(gid_t) + 1;
/* search for duplicate of basegroup */
for (i = j = 1; i < ngroups; i++) {
if (groups[i] != basegroup)
groups[j++] = groups[i];
}
if (j > NGROUPS)
j = NGROUPS;
error = R_setgroups(j, groups);
} else {
SetErrno((nreq->io_Error < 0) ? ENOENT : nreq->io_Error);
}
} else {
SetErrno(ENOENT);
}
ReleaseSemaphore(ni_lock);
return error;
}